<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of questionQCM
 *
 * @author didile
 */
class QuestionQCM {    
    public $id;
    public $question;
    public $propositionArray;
    public $reponse;
    
    
	public function __construct($id='') {
		$this->propositionArray = array();
                if($id != ''){
			$this->id = $id;
			$this->load();
		}
            	
	}
        
        public function load() {
            if(isset($this->id)){
                            $db = Database::getInstance();
                            //On récupère les propositions de réponses et la réponse complète associée à une question
                            $sql= '
                                SELECT distinct q.libelle,q.idQuestion, p.idProposition, r.description,r.idReponse, p.libelle, p.estReponse 
                                FROM question as q, question_proposition as qp, reponse as r , question_reponse as qr, proposition as p
                                WHERE q.idQuestion = qp.idQuestion
                                AND q.idQuestion = qr.idQuestion
                                AND r.idReponse = qr.idReponse
                                AND p.idProposition = qp.idProposition
                                AND qp.idQuestion = '.$this->id.'';					

                            
                               $idReponse = null;
                             //  $i=0;
                             //Stockage des données dans l'objet courant
                            if ($result = $db->fetch($sql)){
                                 foreach($result as $row){ 
                                    $proposition = new Proposition($row['idProposition']);                                  
                                    array_push($this->propositionArray,$proposition);     
                                   // $array[$i]['proposition'] = $row['idRubrique'];
                                    $idReponse = $row['idReponse'];
                                 //   $i++;
                                 }
                                 
                                 $this->question = new Question($this->id);	
                                 $this->reponse = new Reponse($idReponse);
                                    return true;
                            }
                            return false;	
                    }	
	}
	
	public function __toString(){
	
	}
	
}

?>
